//


// 1513833562644
// 1513833117699

var request = require('request');
var cheerio = require('cheerio');
var md5 = require("md5");
var mysql = require('mysql');
var moment = require('moment');
var async = require('async');
 var db = require('./data/config');

var fun = require('./libs/func');


var connection = mysql.createConnection({
   host: db.host,
   user: db.user,
   password: db.password,
   database:db.database
});



var t_time = Date.now();
console.log(t_time )


url = 'https://ajax.lianjia.com/ajax/housesell/area/district?ids=990002%2C510107%2C510108%2C510104%2C510105%2C510106%2C23008850%2C510115%2C510124%2C510112%2C510122%2C510114%2C23009121&limit_offset=0&city_id=510100&_='+t_time;
    var options = {
    	url:url,
    	method: 'GET',
    	charset: "utf-8",
    	headers: {
    		"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36",
    	}
    };

    request(options, function(err, result) {
    	if (err) {
    		console.log(err);
    	}
           html = result.body;
    	//  console.log(html);

        var str = JSON.parse(html);
        console.log(str['data']['total_count']);
        var re = str['data']['total_count'];

            connection.connect();

            console.log(re)

            var addSql  = 'INSERT INTO `lianjia_ditu` ( `areas`, `totals`) VALUES ("成都市", ?);'

			 connection.query(addSql, re, function(err, result) {
    		 	if (err) {
    		 		console.log('[INSERT ERROR] - ', err.message);
                    //
    		 	}
    		 });




connection.end();


})
